<template>
    <div>
        <hd-tab :tabs="tabs" />
        <el-alert effect="light" closable> 正在管理【{{ site.title }}】站点的小程序 </el-alert>
        <el-table :data="lists" style="width: 100%" border v-loading="loading" class="mt-3">
            <el-table-column prop="id" label="编号" width="60" align="center"> </el-table-column>
            <el-table-column prop="title" label="小程序名称"> </el-table-column>
            <el-table-column prop="introduce" label="小程序描述"> </el-table-column>
            <el-table-column label="二维码" #default="{ row }">
                <el-popover placement="top-start" title="扫描二维码关注小程序" width="200" trigger="hover">
                    <template v-slot>
                        <el-image slot="reference" style="width: 150px; height: 150px" :src="row.qr" fit="cover" />
                    </template>
                    <el-image slot="reference" style="width: 50px; height: 50px" :src="row.qr" fit="cover" />
                </el-popover>
            </el-table-column>
            <el-table-column align="center" width="150" #default="{ row}">
                <el-button-group>
                    <el-button type="primary" size="mini" @click="$router.push({ name: 'mini.mini.edit', query: { sid: $route.query.sid, id: row.id } })">
                        编辑
                    </el-button>
                    <el-button type="danger" size="mini" @click="del(row)">删除</el-button>
                </el-button-group>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
import tabs from './tabs'
export default {
    data() {
        return {
            tabs,
            site: {},
            lists: [],
            loading: true
        }
    },
    async created() {
        const sid = this.$route.query.sid
        ;[this.site, this.lists] = await Promise.all([axios.get(`site/${sid}`), axios.get(`site/${sid}/mini`)])
        this.loading = false
    },
    methods: {
        del(list) {
            this.$confirm('确定删除吗？', '温馨提示')
                .then(async () => {
                    await axios.delete(`mini/${list.id}`)
                    this.lists.splice(this.lists.indexOf(list), 1)
                })
                .catch(() => {})
        }
    }
}
</script>

<style></style>
